package com.jia.leetCode;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-21 18:28
 */
public class Pro0115 {
    public int numDistinct(String s, String t) {
        //f[i][j]
        //f[i][j] = f[i-1][j-1]  //s[i] == t[j]
        //
        int n = s.length(), m = t.length();
        int[][] f = new int[n + 1][m + 1];
        for(int i = 0; i <= n; i++) f[i][0] = 1;  //s前i都不匹配t
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                f[i][j] = f[i-1][j];//包括匹配和不匹配
                if(s.charAt(i-1) == t.charAt(j-1)) {
                    f[i][j] += f[i-1][j-1];
                }
            }
        }
        return f[n][m];
    }
}
